home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-11 | 5.4 KB | 242 lines | [TEXT/CWIE] |
- // CTemperatureDoc.cp -- Document methods
-
- #include "CTemperatureDoc.h"
- #include "CTemperatureData.h"
-
- #include "DDocData.h"
- #include "CMainWindow.h"
- #include "TemperatureCmds.h"
-
- #include <LFile.h>
- #include <LPlaceHolder.h>
- #include <LPrintout.h>
- #include <LString.h>
- #include <LWindow.h>
- #include <TArrayIterator.h>
- #include <UWindows.h>
-
- const ResIDT prto_PrintView = 201;
- const ResIDT STRx_Untitled = 128;
-
- // ---------------------------------------------------------------------------
- // • CTemperatureDoc
- // ---------------------------------------------------------------------------
-
- CTemperatureDoc::CTemperatureDoc(
- LCommander *inSuper)
- : LSingleDoc(inSuper)
- {
- mData = new CTemperatureData();
- }
-
- // ---------------------------------------------------------------------------
- // • ~CTemperatureDoc
- // ---------------------------------------------------------------------------
- // Destructor
- //
-
- CTemperatureDoc::~CTemperatureDoc()
- {
- // Delete all SubCommanders - copied from LCommander
- // This fixes a bug that existed in CW11 and prior.
- // It appears that the bug is fixed in CW Pro 1,
- // so this code probably is no longer needed.
- TArrayIterator<LCommander*> iterator(mSubCommanders, LArrayIterator::from_End);
- LCommander* theSub;
- while (iterator.Previous (theSub)) {
- mSubCommanders.RemoveItemsAt (1, iterator.GetCurrentIndex());
- delete theSub;
- }
- mWindow = nil;
-
- delete mData;
- }
-
- //----------
- void
- CTemperatureDoc::newFile()
- {
- mData->NewData();
-
- MakeWindows();
-
- NameNewDoc(); // Set name of untitled window
- }
-
- //----------
- void
- CTemperatureDoc::openFile(
- FSSpec *inFileSpec)
- {
- mData->OpenData (inFileSpec);
-
- MakeWindows();
-
- if (mWindow != nil) {
- mWindow->SetDescriptor (inFileSpec->name);
- }
- mIsSpecified = true;
- }
-
- // ---------------------------------------------------------------------------
- // • MakeWindows
- // ---------------------------------------------------------------------------
-
- void
- CTemperatureDoc::MakeWindows()
- {
- DDocData* docData = mData->GetDocData ();
-
- mMainWindow = CMainWindow::CreateMainWindow(this, docData);
-
- mWindow = mMainWindow;
- }
-
- // ---------------------------------------------------------------------------
- // • NameNewDoc
- // ---------------------------------------------------------------------------
- // Name a new, untitled document window
- //
- // Untitled windows start with "untitled", then "untitled 1",
- // "untitled 2", etc. Old numbers are reused, so there won't be
- // gaps in the numbering.
- //
- // This routine uses a STR# resource to store the "untitled" string,
- // which can be localized to different languages. The first string
- // is "untitled" and the second is "untitled " (trailing space),
- // which is used when appending a number to the name.
-
- void
- CTemperatureDoc::NameNewDoc()
- {
- // Start with the default name("untitled")
- Str255 name;
- ::GetIndString(name, STRx_Untitled, 1);
-
- long num = 0;
- while (UWindows::FindNamedWindow(name) != nil) {
-
- // An existing window has the current name
- // Increment counter and try again
-
- ::GetIndString(name, STRx_Untitled, 2);
- num++;
- Str15 numStr;
- ::NumToString(num, numStr);
- LString::AppendPStr(name, numStr);
- }
-
- mWindow->SetDescriptor(name); // Finally, set window title
- }
- // ---------------------------------------------------------------------------
- // • IsModified
- // ---------------------------------------------------------------------------
- // Return whether the Document has changed since the last save
-
- Boolean
- CTemperatureDoc::IsModified()
- {
- mIsModified = mData->IsDirty();
-
- return mIsModified;
- }
-
- // ---------------------------------------------------------------------------
- // • DoAESave
- // ---------------------------------------------------------------------------
- // Save Document in the specified file with the specified file type
- //
- // If file type is fileType_Default, use the normal file type for
- // this document
-
- void
- CTemperatureDoc::DoAESave(
- FSSpec &inFileSpec,
- OSType inFileType)
- {
- mData->DoSaveAs(&inFileSpec); // Write out data
- // Change window name
- mWindow->SetDescriptor(inFileSpec.name);
- }
-
- //----------
- void
- CTemperatureDoc::DoSave()
- {
- mData->DoSave();
- }
-
- //----------
- void
- CTemperatureDoc::DoRevert()
- {
- mData->DoRevert();
- }
-
- // ---------------------------------------------------------------------------
- // • DoPrint
- // ---------------------------------------------------------------------------
- // Print the contents of the Document
-
- void
- CTemperatureDoc::DoPrint()
- {
- LPrintout *thePrintout = LPrintout::CreatePrintout(prto_PrintView);
- LPlaceHolder *textPlace = (LPlaceHolder *)
- thePrintout->FindPaneByID('TBox');
- //! textPlace->InstallOccupant(mTextView, atNone);
-
-
- thePrintout->DoPrintJob();
- delete thePrintout;
- }
-
- //----------
- Boolean
- CTemperatureDoc::ObeyCommand(
- CommandT inCommand,
- void* ioParam)
- {
- Boolean cmdHandled = true;
-
- if (inCommand < 0) {
- // modal dialog has finished
-
- switch (-inCommand) {
- }
-
- } else {
- switch (inCommand) {
-
- default:
- cmdHandled = LSingleDoc::ObeyCommand(inCommand, ioParam);
- break;
- }
- }
-
- return cmdHandled;
- }
-
- //----------
- void
- CTemperatureDoc::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
- outUsesMark = false;
-
- switch (inCommand) {
-
- // +++ Add cases here for the commands you handle
-
-
- default:
- LSingleDoc::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
-